package com.bosssoft.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bosssoft.entity.po.FibVoucherDetailsPO;
import com.bosssoft.exception.DaoException;
import com.bosssoft.service.FibVoucherDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.entity.po.FibVoucherLocationPO;
import com.bosssoft.mapper.FibVoucherLocationMapper;
import com.bosssoft.service.FibVoucherLocationService;

/**
 * @author Li kexi
 * Created on 2021/8/25.14:17
 */
@Service
public class FibVoucherLocationServiceImpl extends ServiceImpl<FibVoucherLocationMapper, FibVoucherLocationPO> implements FibVoucherLocationService {

    @Autowired
    FibVoucherDetailsService voucherDetailsService;

    @Override
    public List<FibVoucherLocationPO> getListByCode(Integer voucherCode) {
        if (voucherCode == null) {
            throw DaoException.error();
        }
        System.out.println(voucherCode);
        QueryWrapper<FibVoucherLocationPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("voucher_code", voucherCode);
        queryWrapper.orderByAsc("sort");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<FibVoucherLocationPO> getListById(Long voucherId) {
        //判空
        if (ObjectUtil.isNull(voucherId)){
            throw DaoException.error();
        }
        //数据库判空
        FibVoucherDetailsPO byId = voucherDetailsService.getById(voucherId);
        if (byId==null){
            throw DaoException.error();
        }
        Integer voucherCode = byId.getVoucherCode();
        //调用本地方法
        return getListByCode(voucherCode);
    }

    @Override
    public int updateBatch(List<FibVoucherLocationPO> list) {
        return baseMapper.updateBatch(list);
    }

    @Override
    public int updateBatchSelective(List<FibVoucherLocationPO> list) {
        return baseMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert(List<FibVoucherLocationPO> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public int insertOrUpdate(FibVoucherLocationPO record) {
        return baseMapper.insertOrUpdate(record);
    }

    @Override
    public int insertOrUpdateSelective(FibVoucherLocationPO record) {
        return baseMapper.insertOrUpdateSelective(record);
    }
}
